<?
include("/var/www/html/new/com.inc.php");
include("/var/www/html/new/jq/com/errBack.php");
$sceneryId=abs($_REQUEST['sceneryId']);
$ordid=$_REQUEST["ordid"];
$uri=urldecode($_REQUEST["u"]);
//session_start();
if($_SESSION['uu_id']){
	$uu_id=$_SESSION['uu_id'];
}else{
	$uu_id=0;
}
if($_REQUEST['xxid']==999999){
	$sceneryId=999999;
}
if(!$sceneryId){
	leave("/jq/s");
}
//同一ip只能间隔10分钟后才可再次点评
$ip= $_SERVER["REMOTE_ADDR"];
$str="select max(cdate) as cdate from uu_jq_comment where cip='$ip'";
$GLOBALS['le']->query($str);
$GLOBALS['le']->fetch_assoc();
$cdate=$GLOBALS['le']->f("cdate");
$cdate=strtotime($cdate);

if((time()-$cdate)/60<3){
	$wait=3-floor((time()-$cdate)/60);
	echo "<script>alert('你只能在".$wait."分钟后，才能再次点评！');window.location='s_".$sceneryId.".html'</script>";
	exit;
}
$score_fj=abs($_REQUEST['fen']);
if($score_fj>5) {$score_fj=5;}
$score_fw=abs($_REQUEST['fen']);
if($score_fw>5) {$score_fw=5;}
$score_rq=abs($_REQUEST['fen']);
if($score_rq>5) {$score_rq=5;}
if(!$score_fj||!$score_fw||!$score_rq) exit;
$score=($score_fj+$score_fw+$score_rq)/3;
$score=round($score,1);
$cscore=$score."|".$score_fj."|".$score_fw."|".$score_rq;
if($_REQUEST['com_content']){
	if(p_match($_REQUEST['com_content'])) exit;
}
if($_REQUEST['com_title']){
	if(p_match($_REQUEST['com_title'])) exit;
}
$com_content=mysql_real_escape_string($_REQUEST['com_content']);
$com_title=mysql_real_escape_string($_REQUEST['com_title']);
$content=$com_title."|".$com_content;
//输入字符太多，停止运行
if(strlen($content)>1000) exit;
$rec=abs($_REQUEST['rec']);
$cip=$_SERVER['REMOTE_ADDR'];
$str="insert uu_jq_comment set content='".$content."',rec='".$rec."',cdate=now(),cip='".$cip."',memid='$uu_id',landid=".$sceneryId.",cscore='".$cscore."'";

if($GLOBALS['le']->query($str)){
	$now=date("Y-m-d");
	$options=$GLOBALS['_options'];
	$options = array('encoding' =>'UTF-8','cache_wsdl' => 0);
	$s = new SoapClient($GLOBALS['_url'],$options);
	$tdd=$s->__soapCall("Get_Ticket_Order_List",array("ac"=>$GLOBALS['_ac'],"pw"=>$GLOBALS['_pw'],"in0"=>$sceneryId,"in1"=>"",
	"in2"=>"","in3"=>"2012-01-01 00:00:00","in4"=>$now." 23:59:59","in5"=>"","in6"=>$uu_id));
	if(judge($tdd)){}
	elseif($uu_id){
		$tdd=simplexml_load_string($tdd);
		$used=0;
		foreach($tdd as $list){
			if((string)$list->UUstatus=="1"){
				$sel="select id from uu_money_return where ordernum='".$list->UUordernum."'";
				$GLOBALS['le']->query($sel);
				$GLOBALS['le']->fetch_assoc();
				$mid=$GLOBALS['le']->f("id");
				if(!$mid){
					$sel="select reb from uu_jq_ticket where id=".(int)$list->UUtid;
					$GLOBALS['le']->query($sel);
					$GLOBALS['le']->fetch_assoc();
					$reb=$GLOBALS['le']->f("reb");
					$ins="insert into uu_money_return (memid,ordernum,retmoney,rettime) values ('".$memid."','".(string)$list->UUordernum."','".$reb."','".$now."')";
					$GLOBALS['le']->query($ins);
					$upd="update uu_member set money=money+".$reb." where did=".$memid;
					$GLOBALS['le']->query($upd);
					$sel="select money from uu_member where did=".$memid;
					$GLOBALS['le']->query($sel);
					$GLOBALS['le']->fetch_assoc();
					$money=$GLOBALS['le']->f("money");
					$ins="insert into uu_p_money (memid,money,dreason,status,dtime,lmoney) values ('".$memid."','".($reb*100)."','用户评论返还资金','0',now(),'".($money*100)."')";
					$GLOBALS['le']->query($ins);
					break;
				}
			}
		}
	}
	echo "<script>alert('点评成功！');window.location='lypj.html?id=".$sceneryId."&ordid=".$ordid."&u=".urlencode($uri)."'</script>";
}
else{
	echo "<script>alert('点评失败！')</script>";
}
?>